package com.cugmarket.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cugmarket.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    // 查询指定产品下的所有一级评论，按创建时间降序排列（最新的在前）
    @Select("SELECT * FROM comment WHERE product_id = #{productId} AND parent_id IS NULL ORDER BY create_time DESC")
    List<Comment> selectParentComments(String productId);

    // 查询指定产品下某个评论的所有回复，按创建时间升序排列
    @Select("SELECT * FROM comment WHERE product_id = #{productId} AND parent_id = #{parentId} ORDER BY create_time DESC")
    List<Comment> selectChildComments(String productId, String parentId);
}
